package com.hdu.hot100.slideWindow;

import java.util.HashSet;
import java.util.Set;

public class lc3 {
    class Solution {
        public int lengthOfLongestSubstring(String s) {
            Set<Character> set = new HashSet<>();
            int ans = Integer.MIN_VALUE;
            int l = 0, r = 0;
            while (r < s.length())
            {
                char curChar = s.charAt(r);
                while (set.contains(curChar))
                {
                    set.remove(s.charAt(l++));
                }
                set.add(curChar);
                ans = Math.max(ans, r - l + 1);
                r++;
            }
            return ans == Integer.MIN_VALUE ? 0 : ans;
        }
    }
}
